Column

Chart A

Column

Number of stations

Electric

---
title: "Alternative Fuel Stations"
author: "Florian Tanner"
output: 
  flexdashboard::flex_dashboard:
    theme: journal
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(leaflet)
library(tidyverse)
```

```{r}
stations <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-03-01/stations.csv') 
```

```{r}
cols <- ggsci::pal_igv("default")(7)
```

```{r}
public_access <- stations |>  
  janitor::clean_names() |> 
  filter(access_code == "public")  |> 
  mutate(fuel_type= case_when(fuel_type_code == "ELEC" ~ "Electric",
                              fuel_type_code == "BD" ~ "Biodiesel (B20 and above)",
                              fuel_type_code == "CNG" ~ "Compressed Natural Gas (CNG)",
                              fuel_type_code == "E85" ~ "Ethanol (E85)",
                              fuel_type_code == "HY" ~ "Hydrogen",
                              fuel_type_code == "LNG" ~ "Liquefied Natural Gas (LNG)",
                              fuel_type_code == "LPG" ~ "Propane (LPG)"),
         fuel_type = factor(fuel_type, levels = c("Electric", "Ethanol (E85)","Propane (LPG)", "Compressed Natural Gas (CNG)",
                                                     "Biodiesel (B20 and above)","Hydrogen","Liquefied Natural Gas (LNG)")),
         fuel_color = case_when(fuel_type_code == "ELEC" ~ cols[4],
                              fuel_type_code == "BD" ~ cols[1],
                              fuel_type_code == "CNG" ~ cols[3],
                              fuel_type_code == "E85" ~ cols[2],
                              fuel_type_code == "HY" ~ cols[5],
                              fuel_type_code == "LNG" ~ cols[6],
                              fuel_type_code == "LPG" ~ cols[7]))
  
```


```{r}
vectors <- public_access |> 
  select(fuel_color, fuel_type) |> 
  distinct()

color_vector <- vectors$fuel_color
label_vector <- as.character(unique(vectors$fuel_type))
```



Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
leaflet() %>% 
  addTiles() %>% 
  fitBounds(-127.44,24.05,-65.30,50.35) %>% 
  addCircleMarkers(public_access$x, 
                   public_access$y, 
                   color = public_access$fuel_color, 
                   radius = 4, 
                   fill = T,
                   fillOpacity = 0.05,
                   opacity = 0.6,
                   popup = paste(public_access$station_name,
                                 public_access$street_address, 
                                 public_access$fuel_type,
                                 sep = " ")) %>%
  addLegend("bottomleft", 
            colors = color_vector,
            labels = label_vector,
            opacity = 0.8)
```

Column {data-width=350}
-----------------------------------------------------------------------

### Number of stations

```{r}

```

### Electric 

```{r}

```